import pandas as pd
import pickle
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
from __00__config import Config
# 忽略警告信息
import warnings
warnings.filterwarnings('ignore')
# 加载配置
config = Config()


# 设置pandas显示选项
pd.set_option('display.max_columns', None)


# step1:加载模型和向量化器
with open(config.rf_model_save_path, 'rb') as f:
    rf = pickle.load(f)
with open(config.tfidf_model_save_path, 'rb') as f:
    tfidf = pickle.load(f)

# step2:读取dev数据集
df_data = pd.read_csv(config.process_dev_datapath, sep='\t')
words = df_data["words"]

# step3:通过tf-idf进行向量化
features = tfidf.transform(words)

# step4:预测
y_pred = rf.predict(features)
# 打印准确率，精确率，召回率，F1值
print("准确率：", accuracy_score(df_data["labels"], y_pred))
print("精确率：", precision_score(df_data["labels"], y_pred, average='macro'))
print("召回率：", recall_score(df_data["labels"], y_pred, average='macro'))
print("F1值：", f1_score(df_data["labels"], y_pred, average='macro'))
# 打印评估报告
# print(classification_report(df_data["label"], y_pred))

# step5:保存结果
df_data["pred_label"] = y_pred
df_data.to_csv(config.model_predict_result, sep='\t', index=False)
